//
//  ProvinceController.m
//  QuickCure
//
//  Created by 魏根 on 16/9/13.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "ProvinceController.h"
#import "MyProvinceModel.h"
#import "CitysController.h"

static NSString *reuseID = @"province";


@interface ProvinceController ()

@property(nonatomic,strong)NSArray *myProvinceDataArray;

@property(nonatomic,strong)CitysController *citysController;

@end

@implementation ProvinceController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:reuseID];
    
    
    
    
}

//省市数据懒加载
- (NSArray *)myProvinceDataArray{
    
    if (!_myProvinceDataArray) {
        
        _myProvinceDataArray = [MyProvinceModel provinceData];
    }
    return _myProvinceDataArray;
}

#pragma mark ---delegate---

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.myProvinceDataArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
   
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:reuseID forIndexPath:indexPath];
    
    MyProvinceModel *tempModel = self.myProvinceDataArray[indexPath.row];
    
    cell.textLabel.text = tempModel.name;
    
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    _citysController = [[CitysController alloc]init];
    
    MyProvinceModel *tempModel = self.myProvinceDataArray[indexPath.row];
    
    _citysController.citysArray = tempModel.cities;
    
    __weak ProvinceController *weakSelf = self;
    
    _citysController.citysBlock = ^(NSString *cityName){
        
        if (weakSelf.provinceBlock) {
            
            weakSelf.provinceBlock(cityName);

        }
    };
    
    [self.navigationController pushViewController:_citysController animated:YES];
    
}





@end
